﻿package frEngine.core.mesh
{
    import baseEngine.basic.*;
    import baseEngine.core.*;
    import baseEngine.modifiers.*;
    import baseEngine.system.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.*;
    import frEngine.animateControler.*;
    import frEngine.animateControler.keyframe.*;
    import frEngine.animateControler.skilEffect.*;
    import frEngine.core.*;
    import frEngine.event.*;
    import frEngine.manager.*;
    import frEngine.pools.*;
    import frEngine.render.*;
    import frEngine.render.layer.*;
    import frEngine.shader.filters.fragmentFilters.*;
    import frEngine.shader.filters.vertexFilters.*;

    public class SwordLightMesh_Bone extends Mesh3D
    {
        public var toUpdate:Boolean = false;
        public var boneFileter:SwordLightFragmentFilter_Bone;

        public function SwordLightMesh_Bone(param1:String)
        {
            this.boneFileter = new SwordLightFragmentFilter_Bone(null);
            super(param1, false, null);
            this.setMateiralBlendMode(EBlendType.BLEND_LIGHT);
            this.material.materialParams.depthWrite = false;
            this.material.materialParams.twoSided = true;
            setLayer(Layer3DManager.swordLayer, false);
            return;
        }// end function

        override public function setShaderBase(param1:VertexFilter, param2:FragmentFilter) : void
        {
            if (param2 != this.boneFileter)
            {
                this.boneFileter.texture = Global3D.nullBitmapDataTexture;
            }
            super.setShaderBase(param1, this.boneFileter);
            return;
        }// end function

        override protected function setTextureFilter(param1, param2:int) : FragmentFilter
        {
            if (param1 is Texture3D)
            {
                this.boneFileter.texture = param1;
                this.boneFileter.texture.loadPriority = this.loadPriority;
            }
            else
            {
                this.boneFileter.texture = Resource3dManager.instance.getTexture3d(param1, param2, this.loadPriority);
            }
            return this.boneFileter;
        }// end function

        public function reinit(param1:RenderList) : void
        {
            this.renderList = param1;
            return;
        }// end function

        override public function set offsetTransform(param1:Matrix3D) : void
        {
            this.toUpdate = true;
            return;
        }// end function

        override public function get bounds() : Boundings3D
        {
            return null;
        }// end function

        override public function updateChildrenTransform(param1:int = 0) : void
        {
            super.updateChildrenTransform(param1);
            this.toUpdate = true;
            return;
        }// end function

        override public function set curHangControler(param1:Md5SkinAnimateControler) : void
        {
            if (this._curHangControler)
            {
                FrEventDispatcher.instance.proxyRemoveEventListener(this._curHangControler, Engine3dEventName.InitComplete, this.reInitPlaySwordLight);
                FrEventDispatcher.instance.proxyRemoveEventListener(this._curHangControler, Engine3dEventName.TRACK_CHANGE, this.reInitPlaySwordLight);
            }
            super.curHangControler = param1;
            if (_curHangControler)
            {
                FrEventDispatcher.instance.proxyAddEventListener(this._curHangControler, Engine3dEventName.InitComplete, this.reInitPlaySwordLight);
                FrEventDispatcher.instance.proxyAddEventListener(this._curHangControler, Engine3dEventName.TRACK_CHANGE, this.reInitPlaySwordLight);
                this.reInitPlaySwordLight();
            }
            return;
        }// end function

        public function reInitPlaySwordLight(event:Event = null) : void
        {
            var _loc_2:* = this.getAnimateControlerInstance(AnimateControlerType.swordLight_Bone) as SwordLightControler_Bone;
            if (curHangControler == null || _loc_2.length1 == 0)
            {
                return;
            }
            var _loc_3:* = curHangControler.getMeshHangBoneName(this);
            var _loc_4:* = curHangControler.getSwordLightSurface(_loc_3, _loc_2.length1, _loc_2.offsetY, _loc_2.splitNum, _loc_2.rot);
            if (_loc_4)
            {
                this.clearSurface();
                this.addSurface(_loc_4);
                FrEventDispatcher.instance.proxyRemoveEventListener(this._curHangControler, Engine3dEventName.InitComplete, this.reInitPlaySwordLight);
            }
            return;
        }// end function

        override public function getAnimateControlerInstance(param1:int, param2:Modifier = null) : Modifier
        {
            var _loc_3:* = super.getAnimateControlerInstance(param1, param2);
            if (_loc_3 == null)
            {
                switch(param1)
                {
                    case AnimateControlerType.swordLight_Bone:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(SwordLightControler_Bone, this));
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                if (_loc_3)
                {
                    _animateControlerList[param1] = _loc_3;
                    _loc_3.targetObject3d = this;
                    if (_loc_3 is IRender)
                    {
                        this.render = IRender(_loc_3);
                    }
                }
            }
            return _loc_3;
        }// end function

    }
}
